# -*- coding: utf-8 -*-
from datetime import timedelta
from spmi.dm.spmi import spmi_dm__dm_piece_sender_deliver_daily_summary

from utils.operators.cluster_for_spark_sql_operator import SparkSqlOperator

spmi_dm__dm_piece_sender_deliver_month_summary = SparkSqlOperator(
    task_id='spmi_dm__dm_piece_sender_deliver_month_summary',
    task_concurrency=1,
    pool_slots=2,
    master='yarn',
    name='spmi_dm__dm_piece_sender_deliver_month_summary_{{ execution_date | date_add(1) | cst_ds }}',
    sql='spmi/dm/spmi/dm_piece_sender_deliver_month_summary/execute.sql',
    retries=0,
    driver_memory='4G' , 
    driver_cores=2 , 
    executor_cores=4 , 
    executor_memory='5G' , 
    email=['yushuo@jtexpress.com', 'yl_bigdata@yl-scm.com'],
    num_executors=10 , 
    conf={'spark.dynamicAllocation.enabled': 'true',  # 动态资源开启
          'spark.shuffle.service.enabled': 'true',  # 动态资源 Shuffle 服务开启
        'spark.dynamicAllocation.maxExecutors'             : 12 , 
          'spark.dynamicAllocation.cachedExecutorIdleTimeout': 300,  # 动态资源自动释放闲置 Executor 的超时时间(s)
          'spark.sql.sources.partitionOverwriteMode': 'dynamic',  # 允许删改已存在的分区
        'spark.executor.memoryOverhead'             : '2G' ,
          'spark.shuffle.consolidateFiles': 'true',
          'spark.sql.shuffle.partitions': 720,

          },
     hiveconf={'hive.exec.dynamic.partition': 'true',  # 动态分区
               'hive.exec.dynamic.partition.mode': 'nonstrict',
               'hive.exec.max.dynamic.partitions': 200,  # 每天生成 20 个分区
               'hive.exec.max.dynamic.partitions.pernode': 200,  # 每天生成 20 个分区
               },
    yarn_queue='pro',
    execution_timeout=timedelta(hours=2),
)

spmi_dm__dm_piece_sender_deliver_month_summary <<  [
    spmi_dm__dm_piece_sender_deliver_daily_summary
]
